package com.yq.tanhua.net.intercept

import com.fmt.mvi.learn.gobal.log
import com.yq.tanhua.ui.USER_TOKEN
import mmkv.SpUtils
import okhttp3.Interceptor
import okhttp3.Response

/**
 * @author: user
 * @date: 2023/3/13
 */
class HeaderInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val newBuilder = request.newBuilder()
        val token = SpUtils.getString(USER_TOKEN)!!
        "获取到当前token： $token".log()
        newBuilder.addHeader("Authorization", token)

        val proceed = chain.proceed(newBuilder.build())
        return proceed
    }
}